package com.jiguang.shangcheng.dao;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.util.JdbcUtils;
import lombok.SneakyThrows;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class BaseDao{

    @SneakyThrows
    public static Connection getconn() {
        //设置
        DruidDataSource dds = new DruidDataSource();
        dds.setValidationQuery("SELECT 1");
            //1.加载配置文件
            Properties pro = new Properties();
            InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("druid.properties");
            pro.load(is);
            //2.获取连接池对象
            DataSource ds = DruidDataSourceFactory.createDataSource(pro);
            //3.获取连接
            Connection conn = ds.getConnection();
            return conn;

    }
}
